from utils import DateUtil


def generate_text(template, **kwargs):
    return template.format(**kwargs)


def main():
    # 读取模板内容
    with open('../template/english-black-market.en.md', 'r', encoding='utf-8') as file:
        template = file.read()

    # 替换变量
    parameters = {
        'to_name': 'Naira',
        'to_code': 'NGN',
        'from_name': 'US Dollar',
        'from_code': 'USD',
        'rate_date': '2024-06-01',
        'from_value': 1,
        'to_value': 1475
    }

    parameters = {
        'to_name': 'Naira',
        'to_code': 'NGN',
        'from_name': 'Chinese Yuan',
        'from_code': 'CNY',
        'rate_date': '2024-06-01',
        'from_value': 1,
        'to_value': 199
    }

    is_history = False

    if DateUtil.get_current_date() == parameters['rate_date']:
        parameters['today'] = 'Today'
        parameters['today_comma'] = ','
    else:
        parameters['today'] = ''
        parameters['today_comma'] = ''
        is_history = True

    result = generate_text(template, **parameters)

    # 输出结果到新的文件
    if not is_history:
        file_name = '../../frontend/content/Naira/today/{from_name}-to-{to_name}-black-market.en.md'.format(**parameters)
    else:
        file_name = '../../frontend/content/Naira/history/{from_name}-to-{to_name}-black-market.en.md'.format(
            **parameters)
    with open(file_name, 'w', encoding='utf-8') as file:
        file.write(result)


if __name__ == "__main__":
    main()
